<?php
header("Content-Type: text/html; charset=UTF-8", true);

if (!isset ($_GET["query"])){
    echo 'Erro, query de consulta invalida';
    return;
}else{
    
}
include_once $app."dao/dao_consulta.php";
include_once $app."dao/model_cliente.php";
$dao_consulta = new dao_consulta(new model_cliente());

//Mudar em outra consulta
$sql_consulta = "SELECT CLI.CLI_FANTASIA FROM cliente AS CLI INNER JOIN usuario AS USU ON CLI.USU_ID = USU.USU_ID WHERE USU.USU_STATUS LIKE 'A' AND CLI.CLI_FANTASIA LIKE ? limit 30";

$campos = $dao_consulta->select_consulta($sql_consulta, array("%".$_GET["query"]."%"));

$valores = array();
foreach ($campos as $value) {
    $valores [] = $value["CLI_FANTASIA"];
}

echo json_encode(
        Array (
            'query' => $_GET["query"],
            'suggestions' => array_values($valores)
            )
        );
?>